package com.bitland.demo.api;

import lombok.Data;

import java.io.Serializable;

/**
 * @Author:Joe
 * @Date:Created in 11:46  2020/8/10
 * @Description: 公共返回消息体
 */
@Data
public class ResultMsg<T> implements Serializable {
    private int code;
    private String msg;
    private T data;


    public final static String SUCCESS_MESSAGE = "SUCCESS";
    public final static String SYSTEM_ERROR = "系统异常";

    public ResultMsg() {}

    
    public static ResultMsg SUCCESS = new ResultMsg(200, SUCCESS_MESSAGE);

    public ResultMsg(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResultMsg(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static ResultMsg SUCCESS(Object obj) {
        return new ResultMsg(200, SUCCESS_MESSAGE, obj);
    }


    public static ResultMsg ERROR(Object obj) {
        return new ResultMsg(500, SYSTEM_ERROR, obj);
    }
    public static ResultMsg ERROR(int code, String msg, Object obj) {
        return new ResultMsg(code, msg, obj);
    }

    public static ResultMsg ERROR(int code, String msg) {
        return new ResultMsg(code, msg);
    }

}